package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func getTxmMei2() {
	product := openFileMei()

	names := openNameMei()

	txms := make([]string, 0)
	for _, name := range names {
		txm := "无"
		for _, datum := range product.Data.ProductList {
			start := strings.Index(datum.Name, "【")
			end := strings.Index(datum.Name, "】")
			s2 := datum.Name[start+3 : end]
			if s2 == name {
				print(s2)
				//s := fmt.Sprintf("name = %s,value = %.2f", s2, datum.MinActivePrice)

				txm = datum.WmProductSkus[0].SourceFoodCode
			}
		}
		println(txm)
		txms = append(txms, txm)
	}
	writeLineTxmMei2(txms)
}

func writeLineTxmMei2(txms []string) {
	filePtr, err := os.OpenFile("./条形码Mei2", os.O_WRONLY|os.O_CREATE, 0666)
	if err != nil {
		fmt.Println("文件打开失败 [Err:%s]", err.Error())
	}
	defer filePtr.Close()
	//写入文件时，使用带缓存的 *Writer
	write := bufio.NewWriter(filePtr)
	for i := 0; i < len(txms); i++ {
		write.WriteString(txms[i])
		write.WriteString("\n")
	}
	//Flush将缓存的文件真正写入到文件中
	write.Flush()
}
